// 提示语
export const HandleTips = () => {
  const hour = new Date().getHours()
  return hour < 8
    ? `又是元气满满的一天。`
    : hour <= 9
      ? `看到你我好开心。`
      : hour <= 14
        ? `忙碌了一上午，记得吃午饭哦。`
        : hour < 19
          ? `你一定有些累了，喝杯咖啡提提神。`
          : `愿你天黑有灯，下雨有伞。`
}

// 常用功能
export const CommonUseList = [
  {
    img: 'ddcx.png',
    title: '订单查询',
    url: '/order/orderQuery'
  },
  {
    img: 'ddcj.png',
    title: '订单承接',
    url: '/order/customerOrder'
  },
  {
    img: 'kcmxcx.png',
    title: '库存明细查询',
    url: '/inventory/check'
  },
  {
    img: 'cpcx.png',
    title: '产品查询',
    url: '/product/info'
  },
  {
    img: 'khcx.png',
    title: '客户查询',
    url: '/customer/queryCustomer'
  },
  {
    img: 'xydacx.png',
    title: '信用档案查询',
    url: '/credit/custom'
  },
  {
    img: 'shcx.png',
    title: '售后查询',
    url: '/sales/salesOrder'
  },
  {
    img: 'priceListCheck.png',
    title: '客户价目表',
    url: '/customer/priceListCheck'
  },
]

export const BusinessList = [
  {
    img: 'dsh.png',
    title: '待审核订单',
    value: 0,
    key: 'order_audit_total',
  },
  {
    img: 'yshdfh.png',
    title: '已审核待发货',
    value: 0,
    key: 'order_audited_total',
  },
  {
    img: 'dfkdd.png',
    title: '待付款订单',
    value: 0,
    key: 'wait_pay',
  },
  {
    img: 'dshdd.png',
    title: '待收货订单',
    value: 0,
    key: 'order_sent_total',
  },
  {
    img: 'shdd.png',
    title: '售后订单',
    value: 0,
    key: 'refund_total',
  },
]


// echart 图标
import * as echarts from 'echarts'
import { FieldFormat, YAxisDormatCurrency } from '~/src/utils/utils'

const axisLabel: any = {
  show: true,
  textStyle: {
    color: 'rgba(50,68,80,0.8)',
    fontSize: 14,
  },
  margin: 7, //刻度标签与轴线之间的距离
}

const animationDuration = 1500

// Y轴数据格式化
export const YAxisDormat = (v: any) => {
  v = v.toString()
  if (v >= 100000000000) {
    return (v.substring(0, 5) / 10) + '亿'
  } else if (v >= 10000000000) {
    return (v.substring(0, 4) / 10) + '亿'
  } else if (v >= 1000000000) {
    return (v.substring(0, 3) / 10) + '亿'
  } else if (v >= 100000000) {
    return (v.substring(0, 2) / 10) + '亿'
  } else if (v >= 10000000) {
    return v.substring(0, 4) + 'W'
  } else if (v >= 1000000) {
    return v.substring(0, 3) + 'W'
  } else if (v >= 100000) {
    return v.substring(0, 2) + 'W'
  } else if (v >= 10000) {
    return (v.substring(0, 2) / 10) + 'w'
  } else if (v >= 1000) {
    return v
  } else {
    return v
  }
}

export const CustomerOrdersEchart = ({ lines, deal, synchronism, tabIndex }: any) => {

  const tabTitle = tabIndex == 'count' ? '商品数' : '金额'
  const unit = tabIndex == 'count' ? '' : '¥'
  const unitType = tabIndex == 'count' ? 'number' : 'money'
  const radio = tabIndex == 'count' ? 0 : 2

  return {
    animationDuration,
    grid: {
      // 区域
      top: '4%',
      left: '0%',
      right: '2%',
      bottom: '0%',
      containLabel: true,
    },
    tooltip: {
      trigger: 'axis', // 数据项图形触发
      axisPointer: {
        // 坐标轴指示器，坐标轴触发有效
        type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
      },
      axisTick: {
        show: false
      },
      formatter: function (params:any) {
        let relVal = params[0].name
        for (let i = 0, l = params.length; i < l; i++) {
          relVal += '<br/>' +
          params[i].marker +
          params[i]?.seriesName?.substring(0,2) +
          tabTitle +
          '：\n\n' +
          unit +
          FieldFormat(params[i].data, unitType, radio)
        }
        return relVal
      },

    },
    xAxis: {
      show: true,
      type: 'category',
      data: lines,
      axisTick: {
        show: false
      },
      axisLabel: {
        interval: lines.length > 20 ? 1 : 0,
        textStyle: {
          color: '#595959'
        },
        fontFamily: 'PingFangSC-Regular',
        // 默认x轴字体大小
        fontSize: 12,
        // margin:文字到x轴的距离
        margin: 15,
        fontWeight: 400
      },
    },
    yAxis: {
      type: 'value',
      // name: unit,
      nameTextStyle: {
        padding: [10, 50, 10, 10],
        color: '#4E5969',
        fontSize: 12,
        fontWeight: 400
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
      },
      axisLabel: {
        formatter: function (value:any) {
          return YAxisDormatCurrency(value, unit)
        },
        interval: 100,
        textStyle: {
          color: '#595959'
        },
        fontFamily: 'PingFangSC-Regular',
        // 默认x轴字体大小
        fontSize: 12,
        // margin:文字到x轴的距离
        margin: 15,
        fontWeight: 400
      },
      splitLine: {
        show: false
      }
    },
    series: [
      {
        name: '成交量',
        data: deal,
        type: 'line',
        itemStyle: { // 内部线条
          color: '#26E3C0',
        },
        symbol: 'circle',
        smooth: true,
        areaStyle: {
          normal: {
            shadowBlur: 13,
            shadowColor: 'rgba(0,0,0,.2)', // 内部阴影颜色
            shadowOffsetX: 0,
            shadowOffsetY: 10,
            // opacity: 0.4, // 网格和内部背景透明度
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
              {
                offset: 0,
                color: 'rgba(38,227,192,0.04)',
              },
              {
                offset: 1,
                color: 'rgba(38,227,192, 0.2)',
              },
            ]),

          },
        },
      },
      {
        name: '同期数据',
        data: synchronism,
        type: 'line',
        itemStyle: { // 内部线条
          color: '#1456F0',
        },
        symbol: 'circle',
        smooth: true,
        areaStyle: {
          normal: {
            shadowBlur: 13,
            shadowColor: 'rgba(0,0,0,.2)', // 内部阴影颜色
            shadowOffsetX: 0,
            shadowOffsetY: 10,
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
              {
                offset: 0,
                color: 'rgba(20,86,240,0.04)',
              },
              {
                offset: 1,
                color: 'rgba(20,86,240, 0.2)',
              },
            ]),

          },
        },
      },
    ],
  }
}
